package interviewClassic150;

public class CanJump {
    public boolean canJump(int[] nums) {
        //能达到的最远距离
        /*int rightMost = 0;
        for (int i = 0; i < nums.length; i++) {
            if (i <= rightMost) {
                rightMost = Math.max(rightMost,i+nums[i]);
                if (rightMost >= nums.length - 1) return true;
            }
        }

        return false;*/
        int n = nums.length;
        if (n == 1) return true;
        boolean[] dp = new boolean[n];
        dp[0] = true;
        for (int i = 1; i < n; i++) {
            for (int j = i - 1; j >= 0; j--) {
                if (dp[j] && j + nums[j] >= i) dp[i] = true;
            }
        }

        return dp[n - 1];
    }
}
